<template>
	<view class="authList">
		<view class="authTitle">请选择当前身份</view>
		<view v-for="(item,index) in authList" :key="index" class="authItem" @click="selectAuth(item)">
			<view class="avatar">
				<u--image :src="item.icon" shape="square" mode="aspectFill" width="170rpx" height="170rpx"></u--image>
			</view>
			<view class="authInfo">
				<view class="name">{{item.name}}</view>
				<view class="describe">{{item.describe}}</view>
			</view>
			<view class="goIcon">
				<u--image src="/static/right.png" shape="square" mode="aspectFill" width="44rpx" height="44rpx"></u--image>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				authList:[{
					id:"auth_1",
					name:"我是学生",
					describe:"学习课程",
					icon:"/static/auth/1.png"
				},{
					id:"auth_2",
					name:"我是老师",
					describe:"直播开课",
					icon:"/static/auth/2.png"
				},{
					id:"auth_3",
					name:"我是工程师",
					describe:"交流学习",
					icon:"/static/auth/3.png"
				}
				// ,{
				// 	id:"auth_4",
				// 	name:"我是企业",
				// 	describe:"商业合作",
				// 	icon:"/static/auth/4.png"
				// }
				],
				option:{},
				switchPath: ["index", 'community', 'growup', 'my']
			}
		},
		onLoad(option){
			this.option = option;
			this.$request.get(this.$api.getDic,{
				code:"role"
			}).then(res=>{
				this.authList.map((item,index)=>{
					item.value = res[index].value
				})
				uni.hideLoading()
			})
		},
		onShow(){
			// #ifdef MP-WEIXIN  
			if(uni.hideHomeButton){  
			    uni.hideHomeButton();  
			}  
			// #endif
		},
		methods:{
			selectAuth(item){
				uni.getStorage({
					key:"userInfo",
					success: (res) => {
						this.$request.post(this.$api.editUserInfo,{
							id:res.data.id,
							role:item.value
						}).then(info=>{
							uni.setStorage({
								key:"authInfo",
								data:item.value
							})
							let option = this.option;
							if (option.path) {
								if (this.switchPath.indexOf(option.path)>-1) {
									uni.switchTab({
										url: "/pages/" + option.path + '/' + option.path+'?'+this.paramsUrl(option)
									})
								} else {
									uni.redirectTo({
										url: "/pages/" + option.path + '/' + option.path+'?'+this.paramsUrl(option)
									})
								}
							}else{
								uni.switchTab({
									url: "../index/index"
								})
							}
							uni.hideLoading()
							uni.showToast({
								icon:"success",
								title:"登录成功"
							})
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.authList{
		display: flex;
		flex-direction: column;
		overflow: auto;
		background-color: #F5F6F8;
		padding-bottom: 40rpx;
		.authTitle{
			color: #333;
			font-size: 48rpx;
			font-weight: 600;
			padding-left: 40rpx;
			padding-top: 40rpx;
		}
		.authItem{
			display: flex;
			justify-content: space-around;
			padding: 18px;
			margin: 40rpx 40rpx 0 40rpx;
			border-radius: 20rpx;
			background-color: #fff;
			align-items: center;
			.avatar{
				width: 170rpx;
				height: 170rpx;
				display: inline-block;
			}
			.authInfo{
				width: calc(100vw - 200rpx);
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				justify-content: center;
				padding-left: 32rpx;
				.name{
					font-size: 34rpx;
					font-weight: bold;
					color: #333;
					margin-bottom: 20rpx;
				}
				.describe{
					font-size: 26rpx;
					color: #666;
				}
			}
		}
	}
</style>
